package com.x.erp.dao;

import com.x.erp.model.MultilevelActivityCash;
import com.x.framework.dao.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * 多级营销提现记录DAO
 */
@Repository
public class MultilevelActivityCashDao extends BaseDao {

	private final static String selectMultilevelActivityCashListSql = "SELECT " +
			"emac.* " +
			"FROM " +
			"erp_multilevel_activity_cash emac " +
			"WHERE " +
			"1 = 1 ";
	/**
	 * 查询提现记录列表
	 * @param multilevelActivityCash
	 * @return
	 * @throws Exception
	 */
	public List<MultilevelActivityCash> selectMultilevelActivityCashList(MultilevelActivityCash multilevelActivityCash) throws Exception{
		StringBuilder sql = new StringBuilder(selectMultilevelActivityCashListSql);
		List<Object> params = new ArrayList<>();
		searchCondition(sql, params, multilevelActivityCash);
		return this.queryForList(sql.toString(), MultilevelActivityCash.class, params);
	}

	private final static String selectMultilevelActivityCashNumSql = "SELECT " +
			"count(1) " +
			"FROM " +
			"erp_multilevel_activity_cash emac " +
			"WHERE " +
			"1 = 1 ";
	/**
	 * 查询提现记录列表数量
	 * @param multilevelActivityCash
	 * @return
	 * @throws Exception
	 */
	public Integer selectMultilevelActivityCashNum(MultilevelActivityCash multilevelActivityCash) throws Exception{
		StringBuilder sql = new StringBuilder(selectMultilevelActivityCashNumSql);
		List<Object> params = new ArrayList<>();
		searchCondition(sql, params, multilevelActivityCash);
		return this.queryForInt(sql.toString(), params);
	}

	/**
	 * 查询条件
	 * @param sql
	 * @param params
	 * @param multilevelActivityCash
	 */
	private void searchCondition(StringBuilder sql, List<Object> params, MultilevelActivityCash multilevelActivityCash) {
		if(multilevelActivityCash != null) {
			if(multilevelActivityCash.getUserId() != null){
				sql.append("AND emac.USER_ID = ? ");
				params.add(multilevelActivityCash.getUserId());
			}
		}
	}
}
